import 'dart:developer';
import 'dart:typed_data';

import 'package:kmxy_base/page/signature/signature_page_view.dart';
import 'package:kmxy_base/base/base_package.dart';
import 'package:signature/signature.dart';

abstract class SignaturePageState extends BasePageState<SignaturePage> {
  SignatureController controller = SignatureController(
    penStrokeWidth: 5,
    penColor: Colors.black,
    exportBackgroundColor: Colors.white,
  );

  @override
  initData() {}

  @override
  destroyData() {}

  clean() {
    controller.clear();
  }

  save() async {
    Uint8List? uint8List = await controller.toPngBytes();
    if (uint8List != null) {
      String signaturePath = await FileUtil.uint8List2File(uint8List);
      finishPop(context, callBackData: {'path': signaturePath});
    } else {
      finishPop(context, callBackData: {'path': ''});
    }
  }
}
